course.admin = liwe.module ( 'course.admin', null, "Corsi" );

course.admin._dest_div = "system-content";
course.admin._visiblecnt = {};
course.admin._id_course = 0;
course._course_opts = null;
course._calendar_opts = null;
course._user_opts = null;
course._settings = null;
course.admin.pop = new WWL.popbox ( 'course_card' );
//{{{course.admin._init = function ( dest_div 
course.admin._init = function ( dest_div )
{
	if ( dest_div ) course.admin._dest_div =  dest_div;
	var _acts = [
		{ label: 'Corsi', func: function () { course.admin._load_section( 'course' );} }
		//{ label: 'Calendario', func: function () { course.admin._load_section ( 'calendar' ); } },
		//{ label: 'Pagamenti', func: function () { course.admin._render (); } },
		//{ label: 'Impostazioni', func: function () { course.admin._render (); } }
	];

        var _plugin = [
                {
                        label:   "Inserisci Corso",
                        handler: course.admin._jconed_handler,
                        context: course.admin._jconed_context
                },
				{
						label: "Corsi Imminenti",
						handler : course.admin._jconed_incoming_hd,
						context : course.admin._jconed_incoming_ctx
				}
        ];

	course.admin.register ( _acts, _plugin );
	course.admin._am_course_init ( 'co_course_list' );
	course.admin._am_charge_init ( 'co_charge_list' );
	course.admin._am_calendar_init ( 'co_calendar_list' );
	course.admin._am_user_init ( 'co_user_list' );
	course.admin._get_settings ();
	course.admin._set_course_opts ();
};
//}}}
//{{{course.admin._get_settings = function ( cback )
course.admin._get_settings = function ( cback )
{
	course._settings = {};
	var _post = { 'action' : 'course.admin.get_settings' };
	course.ajax ( _post, function ( _resp )
	{
		course._settings = _resp.setting;
		liwe.types.to_dict ( course._settings );
		if ( cback ) cback ();
	} );
};
//}}}
//{{{course.admin._set_user_opts = function ( cback )
course.admin._set_user_opts = function ( cback )
{
	course._user_opts = {};
	var post = { 'action' : 'course.admin.list_all' };
	course.ajax ( post, function ( resp )
	{
		var l = [ 'teacher', 'student' ];
		l.iterate ( function ( v )
		{
			course._user_opts [ v ] = [];
			var u = resp [ v ] ;
			u.iterate ( function ( item )
			{
				course._user_opts [ v ].push ( { 'label' : item [ 'login' ], 'value' : item  [ 'uid' ] } );
			} );
		} );
	} );
	if ( cback ) cback();
};
//}}}
//{{{course.admin._get_user_mail = function ( kind, uid )
course.admin._get_user_mail = function ( kind, uid )
{
	
	var _opts = course._user_opts  [ kind ];
	var _i, _item;
	var res = '';
	for  ( i = 0; i < _opts.length; i++ )
	{
		_item =  _opts [ i ];
		if ( _item [ 'value' ] == uid )
		{
			res = _item;
			break;
		};
	};		
	return  res;

};
//}}}
//{{{course.admin._set_calendar_opts = function ( id_course, cback )
course.admin._set_calendar_opts = function ( id_course, cback )
{
	var _post  = { 'action' : 'course.ajax.list_calendar', 'mode' : 'valid' , 'id_course' : id_course };
	course.ajax ( _post, function ( _resp )
	{
		course._calendar_opts = [];
		_resp.calendar.iterate ( function ( item )
		{
			var _date = Date.formatted ( "%d %B %Y", item [ 'start_date' ].split( " ") [ 0 ]); 
			course._calendar_opts.push ( { 'label' : _date, 'value' : item [ 'id' ] } );
		});
		if ( cback ) cback();
	} );
};
//}}}
//{{{course.admin._set_course_opts = function ( cback )
course.admin._set_course_opts = function ( cback )
{
	var _post = { 'action' : 'course.ajax.list_course_plain' };
	course.ajax ( _post, function ( _resp )
	{
		course._course_opts = [];
		_resp.course.iterate ( function ( item )
		{
			course._course_opts.push ( { 'label' : item [ 'name' ], 'value' : item  [ 'id' ] } ); 
		});
		if ( cback ) cback();
	} ); 

};
//}}}
//{{{course.admin._load_section = function ( section )
course.admin._load_section = function ( section )
{
	course.admin._visiblecnt = { 'course' :  '', 'charge' : '', 'calendar' : '', 'user' : '' };
	var _func = course.admin [ "_render_" + section ];
	_func ();
};
//}}}
//{{{course.admin._show_cnt = function ( cnt_to_show, section )
course.admin._show_cnt = function ( cnt_to_show, section )
{
	var _el;
	if ( course.admin._visiblecnt [ section ] != '' )
	{ 
		liwe.fx.fade_out ( course.admin._visiblecnt [ section ] );
		_el = $el ( course.admin._visiblecnt [ section ] );
		_el.style.display = "none";
	};
	_el = $el ( cnt_to_show );
	_el.style.display = "block";
	liwe.fx.fade_in ( cnt_to_show );
	course.admin._visiblecnt [ section ] = cnt_to_show;
};
//}}}
//{{{course.admin._show_dett = function ( section )
course.admin._show_dett = function ( section )
{
	var el =  $ ( "co_dettaglio_panel" )
	if ( el.style.display == "block" ) return;

	el.style.display = "block";
	liwe.fx.fade_in ( "co_dettaglio_panel" );
}
//}}}
//{{{course.admin._hide_dett = function ( section )
course.admin._hide_dett = function ( section )
{
	var el =  $ ( "co_dettaglio_panel" )
	if ( el.style.display == "none" ) return;

	liwe.fx.fade_out ( "co_dettaglio_panel", function () { el.style.display = "none"; } );
}
//}}}
//{{{course.admin._get_id_course = function ()
course.admin._get_id_course = function ()
{
	if  ( $el ( "co_course_form" ).innerHTML )
	{
		var _fcourse = liwe.form.get ( 'am_course_form' );
		if ( typeof ( _fcourse ) != 'undefined' ) course.admin._id_course =  _fcourse.get_value ( 'id_course' );
	};
	return course.admin._id_course;
}
//}}}
//{{{COURSE
//{{{course.admin._render_course =  function()
course.admin._render_course =  function()
{
	var _dct, _admin_title;
	var _ceck_setting = true;
	var _td_buff = new String.buffer();
	course._settings.iterate ( function ( setting, key )
	{
		_admin_title = String.formatDict ( course.templates [ 'ADMIN_TITLE' ], { '_title' : 'Controllo Settaggi' } );
		_dct =  { '_attr' : key, '_value' : setting, '_icon' : 'bullet_green' };
		if ( setting == 0 ) 
		{
			_dct [ '_icon' ] = 'bullet_red';
			_ceck_setting = false;
		};
		_td_buff.add ( String.formatDict ( course.templates [ 'ADMIN_SETTING_ROW' ], _dct ) );
	});
	if ( _ceck_setting == false )
	{
		_dct =  { '_admin_title' : _admin_title, '_sett_row' : _td_buff.toString() };
		$ ( course.admin._dest_div, String.formatDict ( course.templates [ 'ADMIN_SETTING_LAYOUT' ], _dct ) );
		return;
	};

	course.admin._set_user_opts ( function ()
	{
		//charge
		_dct = { '_admin_title' : '', '_list_title' : 'Tipologie di pagamento', '_form_title' : "Inserimento/modifica tipo pagamento" };
		var _charge = String.formatDict ( course.templates [ 'ADMIN_CHARGE_LAYOUT' ] , _dct  );
		var _admin_title = String.formatDict ( course.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE CORSI' } ); 

		_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco', '_form_title' : "Inserimento/modifica corso", '_charge' : _charge };
		$( course.admin._dest_div, String.formatDict ( course.templates [ 'ADMIN_COURSE_LAYOUT' ], _dct ) );
		course.admin._course_refresh ();
	});

};
//}}}
//{{{course.admin._am_course_init = function ( dest_div )
course.admin._am_course_init = function ( dest_div )
{
        if ( course.admin.am_course ) return;
        course.admin.am_course = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_course',
                                        'list_action': "course.ajax.list_course",
										'del_action' : "course.admin.del_course",
                                        'mod_menu_actions': [ { func: "course.admin._course_form();", 'class' : 'add' , label: 'Aggiungi Corso' } ],
										'filter_form' : course.admin._course_filter_form,
										'filter_form_name' : "am_course_filter"
                                } );

        course.admin.am_course.set_row_fields (
                                [
                                        [ "ID", "id" ],
                                        [ "Visibile", "_active" ],
                                        [ "Titolo", "name" ],
                                        [ "Durata", "day_duration" ],
                                        [ "Numero massimo di iscritti", "places" ],
                                        [ "Data Inserimento", "_created" ]
                                ]
                                );
		course.admin.am_course.set_row_actions ( 
							[ 
								[ course.templates [ 'ADMIN-COURSE-ACTION-CHARGE' ], "charge" ],
								[ course.templates [ 'ADMIN-COURSE-ACTION-CALENDAR' ], "calendar" ],
								[ course.templates [ 'ADMIN-COURSE-ACTION-USER' ], "user" ]
							] );

		course.admin.am_course.cbacks [ 'charge' ] = function ( id ) { course.admin._show_charge ( id ); };
		course.admin.am_course.cbacks [ 'calendar' ] = function ( id ) { course.admin._show_calendar ( id ); };
		course.admin.am_course.cbacks [ 'user' ] = function ( id ) { course.admin._show_user ( id ); };

        course.admin.am_course.cbacks [ 'row_manip' ] = course.admin._rwman_course;
        course.admin.am_course.cbacks [ 'del_item' ]  = function ( id ) { course.admin.del_course ( id ); };
        course.admin.am_course.cbacks [ 'edit_item' ]  = function ( id ) { course.admin.edit_course ( id ); };
        course.admin.am_course.cbacks [ 'noresult' ] = function () { course.admin._course_form(); };
        course.admin.am_course.cbacks [ 'show_results' ] = function () { course.admin._show_cnt ( 'co_course_panel_list', 'course' ); };


	course.admin.am_course.templates [ 'actions_row_action' ] = course.templates [ 'ADMIN-ROW-ACTION' ];
};
//}}}
//{{{course.admin._course_filter_form = function ( dest_div )
course.admin._course_filter_form = function ( dest_div )
{
	var f = new liwe.form5.instance ( "am_course_filter" );
	
	f.add ( "select", "visible", { label : "Visibilit&agrave;", 
									  options : [ { 'label' : "Nascosti", value : 0 } ,
												  { 'label' : "Visibili", value : 1 },
											      { 'label' : "Tutti", value : -1 } 
												], value :1 
									} );
	f.add ( "tags" , "tags", { label: "Tags" } );
	f.add ( "checkbox", "nodates", { label : "Non ha date",  checked: false, value : "1" } );
	f.add ( "checkbox", "validdates", { label : "Non ha date valide a partire da oggi",  checked: false, value : "1" } );
	f.add ( "checkbox", "incoming", { label : "Solo Corsi con date valide da oggi",  checked: false, value : "1" } );
	f.add ( "submit" , "invia", { value : "Filtra", class : "button green" } );

	f.addEventListener ( "submit", course.admin._course_filter_apply );
	f.set ( dest_div, course.templates [ 'ADMIN-COURSE-FILTER' ] )
};
course.admin._course_filter_apply = function ()
{
    course.admin.am_course.search_start ();
    return false;
};
//}}}
//{{{course.admin._rwman_course = function ( ds, row )
course.admin._rwman_course = function ( ds, row )
{
    row [ "_id" ] = row [ 'id' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]); 
	var _bullet =  [ 'off', 'on' ];
	var _visible = row [ 'visible' ];
	row [ '_active' ] = String.formatDict ( course.templates [ 'ADMIN_ON_OFF'], { '_class' : _bullet [ _visible ] , '_id' : row [ '_id' ] } );
};
//}}}
//{{{course.admin._course_refresh =  function ( cback )
course.admin._course_refresh =  function ( cback )
{
	$ ( "co_course_form", "" );
	course.admin.am_course.show_list ();
	if ( cback ) cback();
};
//}}}
//{{{course.admin.edit_course = function ( id )
course.admin.edit_course = function ( id )
{
        var _post = { action : 'course.ajax.get_course', id_course : id };
        course.ajax ( _post , function ( _resp )
        {      
		course.admin._course_form ( _resp.course );
        });
};
//}}}
//{{{course.admin.del_course = function ( ids )
course.admin.del_course = function ( ids )
{
	var answer = confirm("Sei sicuro di vole cancellare questo corso?");
	if ( answer )
	{
		var v = { 'action' : 'course.admin.del_course', 'ids' : ids };
		course.admin.ajax ( v , function ()
		{
			liwe.utils.notifier.show ( 'Corso/i Eliminato/i', 'info', 2000)
			course.admin.am_course.show_list();
		});
	} else {
		return;
	};
};  
//}}}
//{{{course.admin.set_course_visible = function ( el, id_course )
course.admin.set_course_visible = function ( el, id_course )
{
	var visible = 1;
	var new_class = "on"
	var old_class = "off"
	if ( liwe.dom.has_class ( el, "on" ) ) 
	{
		visible = 0;
		new_class = "off";
		old_class = "on";
	}
	var post = { 'action' : 'course.admin.set_course_visible',
				 'id_course' : id_course, 
				 'visible' : visible }
	course.ajax ( post , function ()
	{
		var  el_onoff = $el ( "visible_" + id_course );
		liwe.dom.del_class ( el_onoff, old_class );
		liwe.dom.add_class ( el_onoff, new_class );		
	} );

}
//}}}
//{{{course.admin._course_save =  function ()
course.admin._course_save =  function ( frm , vals )
{
	var f = liwe.form.get ( 'am_course_form' );
	f.set_value ( 'id_course', frm.course [ 'id_course' ] );
	
	liwe.utils.notifier.show ( 'Corso Salvato correttamente', 'info', 2000);
	course.admin._set_course_opts ( function () { course.admin._course_extra (); } );
	
};
//}}}
//{{{course.admin._course_form =  function ( data )
course.admin._course_form =  function ( data )
{
	$ ( "co_dettaglio", "" );
	var dest_div = 'co_course_form';
	if ( typeof ( data ) == 'undefined' ) data = {};
	var f = new liwe.form.instance ( 'am_course_form' );
	f.events [ 'complete' ] = course.admin._course_save;
	f.hidden ( "action", 'course.admin.set_course' );
	f.hidden ( 'id_course', data.get ( 'id', 0 )  );
	f.text ( { 'label' : 'Titolo' , 'name' : 'name' , 'colspan' : 4, size : 40, 'maxlength' : 100, 'value' : data.get ( 'name' , '' ) } );
	f.text ( { 'label' : 'Prodotto Associato' , 'name' : 'product_code' , 'colspan' : 4, size : 40, 'maxlength' : 100, 'value' : data.get ( 'product_code' , '' ) } );
	f.text ( { 'label' : 'Citt&agrave;' , 'name' : 'city' , size : 40, 'maxlength' : 50, 'value' : data.get ( 'city' , '' ) } );
	f.jconed ( { 'label' : 'Indirizzo', 'name' : "address", width: 300, height: 50, colspan : 3, 'value' : data.get ( 'address' , '' ) } );
	f.number ( { 'label' : 'Durata (gg)', 'name' : 'day_duration' , size : 10, 'maxlength' : 10, 'value' : data.get ( 'day_duration', 1 ) } );
	f.number ( { 'label' : 'Posti' , 'name' : 'places' , size : 10, 'maxlength' : 10, 'value' : data.get ( 'places' , 1 ) } );
	f.check_box ( { label: 'Visibile', name: 'visible', checked : !!parseInt ( data.get ( 'visible', 1 ) ), 'value' : 1  } );
	f.text ( { 'label' : 'Url' , 'name' : 'url' , 'colspan' : 4, size : 40, 'maxlength' : 400, 'value' : data.get ( 'url' , '' ) } );
	f.check_box ( { label: 'Apri Url in una nuova pagina', name: 'new_page', checked : !!parseInt ( data.get ( 'new_page', 0 ) ), 'value' : 1  } );
	f.tags ( { label: 'Tags', name: 'tags', module_name: "course", 'value' : tags.convert ( data.get ( 'tags' , '' )  ) } );
	f.jconed ( { 'label' : 'Descrizione breve', 'name' : "desc_breve", width: 300, height: 200, 'value' : data.get ( 'desc_breve' , '' ) } );
	f.jconed ( { 'label' : 'Descrizione', 'name' : "descr", width: 300, height: 200, 'value' : data.get ( 'descr' , '' ) } );
	f.jconed ( { 'label' : 'Note', 'name' : "note", width: 300, height: 100, 'value' : data.get ( 'note' , '' ) } );
	f.submit ( { value: 'Salva', 'class' : "button green",nonl : true, colspan : 2 } );
	f.button ( { value: 'Indietro', 'class' : "grey", onclick : "course.admin._course_refresh()"} );
	f.set ( dest_div );
	course.admin._show_cnt ( 'co_course_panel_form', 'course' );
	if ( data.get ( 'id', 0 ) != 0 )
	{
		course.admin._course_extra ();
	};
		
};
//}}}
//{{{course.admin._course_extra = function ( )
course.admin._course_extra = function ( )
{
	course.admin._charge_refresh ();
	course.admin._init_tabs();
	
	var _dct = { '_admin_title' : '', '_list_title' : 'Calendario Corsi', '_form_title' : "Inserimento/modifica Calendario" };
	$( 'co_calendar_tab', String.formatDict ( course.templates [ 'ADMIN_CALENDAR_LAYOUT' ] , _dct  ) );
	course.admin._calendar_refresh ();

	var _dct = { '_admin_title' : '', '_list_title' : 'Utenti Registrati', '_form_title' : "Inserimento/modifica Utenti" };
	$( 'co_user_tab', String.formatDict ( course.templates [ 'ADMIN_USER_LAYOUT' ] , _dct  ) );
	course.admin._user_refresh ();

	course.admin._tabs.send_event ( 'co_calendar_tab', 'click' );
	
};
//}}}
//{{{course.admin._init_tabs = function ()
course.admin._init_tabs = function ()
{
	var s = new String.buffer ();
	var res;
	if ( ! course.admin._tabs ) course.admin._tabs = new OS3Tabs.instance ( 'co_tabs' );

	course.admin._tabs.clear ();

	s.add ( course.templates [ 'ADMIN_COURSE_TABS_START' ] );

	s.add ( String.formatDict ( course.templates [ 'ADMIN_COURSE_TAB' ], { "tab_name" : "co_calendar_tab" } ) );
	course.admin._tabs.add ( 'Calendario', 'co_calendar_tab' );
	s.add ( String.formatDict ( course.templates [ 'ADMIN_COURSE_TAB' ], { "tab_name" : "co_user_tab" } ) );
	course.admin._tabs.add ( 'Iscritti', 'co_user_tab' );
	s.add ( String.formatDict ( course.templates [ 'ADMIN_COURSE_TAB' ], { "tab_name" : "co_stats_tab" } ) );
	course.admin._tabs.add ( 'Statistiche', 'co_stats_tab' );

	s.add ( course.templates [ 'ADMIN_COURSE_TABS_END' ] ); 

	res = s.toString ();
	$( 'co_course_tabs', res );
	course.admin._tabs.render ();
};
//}}}
//{{{ AM_COURSE CUSTOM CBACK _show_charge _show_calendar  _show_user
course.admin._show_charge = function ( id_course )
{

	var _dct = { '_admin_title' : '', '_list_title' : 'Tipologie di pagamento', '_form_title' : "Inserimento/modifica tipo pagamento" };
	$( 'co_dettaglio', String.formatDict ( course.templates [ 'ADMIN_CHARGE_LAYOUT' ] , _dct  ) );
	$( 'co_teaser' , String.formatDict ( course.templates [ 'ADMIN_COURSE_TEASER' ] ,course.admin._get_course_row ( id_course ) ) );
		
	course.admin._id_course =  id_course;
	course.admin._charge_refresh (	function () {  course.admin._show_dett ( "charge" ) } );
	
} 
course.admin._show_calendar = function ( id_course )
{
	var _dct = { '_admin_title' : '', '_list_title' : 'Calendario Corsi', '_form_title' : "Inserimento/modifica Calendario" };
	$( 'co_dettaglio', String.formatDict ( course.templates [ 'ADMIN_CALENDAR_LAYOUT' ] , _dct  ) );
	$( 'co_teaser' , String.formatDict ( course.templates [ 'ADMIN_COURSE_TEASER' ] , course.admin._get_course_row ( id_course ) ) );

	course.admin._id_course =  id_course;
	course.admin._calendar_refresh ( function () { course.admin._show_dett ( "calendar" ) } );

} 
course.admin._show_user = function ( id_course )
{
	var _dct = { '_admin_title' : '', '_list_title' : 'Utenti Registrati', '_form_title' : "Inserimento/modifica Utenti" };
	$( 'co_dettaglio', String.formatDict ( course.templates [ 'ADMIN_USER_LAYOUT' ] , _dct  ) );
	$( 'co_teaser' , String.formatDict ( course.templates [ 'ADMIN_COURSE_TEASER' ] , course.admin._get_course_row ( id_course ) ) );

	course.admin._id_course =  id_course;

	course.admin._user_refresh ( function () { course.admin._show_dett ( "user" ); })
}
course.admin._get_course_row = function ( id_course )
{
	var rows = course.admin.am_course._ds.rows;
	
	for ( k  in rows )
	{
		if ( typeof ( rows [ k ] ) == 'function' ) continue;
		var row = rows [ k ];
		if ( row [ '_id' ] == id_course ) break;
	};

	return row;
}
course.admin.show_user_card  = function ( ev,  el, uid )
{
	var pop_id = "popbox:course_card";
	course.admin.pop.set_parent ( el, "B" );
	course.admin.pop.set_size ( 400, 200 );
	course.admin.pop.set_delta ( -6, 27 );

	course.admin.pop.show();
	var post = { 'action' : 'address_book.ajax.get_profile', 'uid' : uid }
	course.ajax ( post , function ( resp )
	{
		$( pop_id, String.formatDict ( course.templates [ 'ADMIN_CARD_BOX' ], resp.profile ) );
	} );
	ev.stopPropagation();
	liwe.events.once ( document, 'click', course.admin.hide_card );
}
course.admin.hide_card = function ()
{
	course.admin.pop.hide();
}
//}}
 
//}}}
//{{{CHARGE
course.admin._render_charge = function ()
{
	return
};

//{{{course.admin._am_charge_init = function ( dest_div )
course.admin._am_charge_init = function ( dest_div )
{
        if ( course.admin.am_charge ) return;
        course.admin.am_charge = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_charge',
                                        'list_action': "course.ajax.list_charge",
					'del_action' : "course.admin.del_charge",
                                        'mod_menu_actions': [
                                                                 { func: "course.admin._charge_form();", 'class' : 'add' , label: 'Aggiungi Corso' }
					],
					'filter_form' : course.admin._charge_filter_form,
					'filter_form_name' : "am_charge_filter"
                                } );

        course.admin.am_charge.set_row_fields (
                                [
                                        [ "ID", "id" ],
                                        [ "Corso", "course" ],
                                        [ "Coupon", "product_coupon" ],
                                        [ "Nome", "descr" ],
                                        [ "Giorni anticipo", "_day_before" ],
                                        [ "Costo", "_value" ],
                                        [ "Iva", "_tax_code" ],
                                        [ "Costo + IVA", "_net_value" ],
                                        [ "Data Inserimento", "_created" ]
                                ]
                                );

        course.admin.am_charge.cbacks [ 'row_manip' ] = course.admin._rwman_charge;
        course.admin.am_charge.cbacks [ 'del_item' ]  = function ( id ) { course.admin.del_charge ( id ); };
        course.admin.am_charge.cbacks [ 'edit_item' ]  = function ( id ) { course.admin.edit_charge ( id ); };
        course.admin.am_charge.cbacks [ 'noresult' ] = function () { course.admin._charge_form(); };
        course.admin.am_charge.cbacks [ 'show_results' ] = function () { course.admin._show_cnt ( 'co_charge_panel_list', 'charge' ); };
};
//}}}
//{{{course.admin._address_filter_form = function ( dest_div )
course.admin._charge_filter_form = function ( dest_div )
{
	course.admin._get_id_course ();
	var f = new liwe.form.instance ( "am_charge_filter" );
	f.hidden ( "id_course",  course.admin._id_course );
	f.set ( dest_div );
};
//}}}
//{{{course.admin._rwman_charge = function ( ds, row )
course.admin._rwman_charge = function ( ds, row )
{
	row [ "_id" ] = row [ 'id' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]) ; 
	var _dct = { '_class' : 'money' };
	_dct [ '_txt' ] ='€ ' +  Money.fromLongInt ( row [ 'value' ] ) ;
	row [ "_value" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
	var _dct = { '_class' : 'number' };
	_dct [ '_txt' ] = ( row [ 'tax_code' ] ) ;
	row [ "_tax_code" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );

	
	var tax_code = row.get ( 'tax_code' , 0 );
	var value = row.get ( 'value', 0 );
	var net_value = Math.round ( value * (tax_code + 100) / 100 ); 
	_dct [ '_txt' ] ='€ ' +  Money.fromLongInt ( net_value ) ;

	row [ "_net_value" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
	
	_dct [ '_txt' ] = ( row [ 'day_before' ] ) ;
	row [ "_day_before" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
};
//}}}
//{{{course.admin._charge_refresh =  function ( cback )
course.admin._charge_refresh =  function ( cback )
{
    course.admin.am_charge.show_list ();
	if ( cback ) cback();
};
//}}}
//{{{course.admin.edit_charge = function ( id )
course.admin.edit_charge = function ( id )
{
        var _post = { action : 'course.ajax.get_charge', id_charge : id };
        course.ajax ( _post , function ( _resp )
        {      
		course.admin._charge_form ( _resp.charge );
        });
};
//}}}
//{{{course.admin._charge_save =  function ()
course.admin._charge_save =  function ()
{
	course.admin._charge_refresh ( function () 
	{
		liwe.utils.notifier.show ( 'Costo Salvato correttamente', 'info', 2000)
	});	
};
//}}}

course.admin.del_charge = function ( ids )
{
	var answer = confirm("Sei sicuro di vole cancellare questa tipolodia di pagamento?");
	if ( answer )
	{
		var v = { 'action' : 'course.admin.del_charge', 'ids' : ids };
		course.admin.ajax ( v , function ()
		{
			liwe.utils.notifier.show ( 'Tipogia/e elimanta/e', 'info', 2000)
			course.admin.am_charge.show_list();
		});
	} else {
		return;
	};
};   
//{{{course.admin._charge_form =  function ( data )
course.admin._charge_form =  function ( data )
{
	var dest_div = 'co_charge_form';
	if ( typeof ( data ) == 'undefined' ) 
	{
		data = {};
		var _fcourse = liwe.form.get ( 'am_course_form' );
		if ( typeof ( _fcourse ) != 'undefined' )
		{
			data [ 'id_course' ] =  _fcourse.get_value ( 'id_course' );
		};
	};
	var _f = new liwe.form.instance ( 'am_charge_form' );
	_f.events [ 'complete' ] = course.admin._charge_save;
	_f.hidden ( "action", 'course.admin.set_charge' );
	_f.hidden ( 'id_charge', data.get ( 'id', 0 )  );
	_f.hidden ( 'id_course', data.get ( 'id_course', 0 )  );
	_f.text ( { 'label' : 'Titolo' , 'name' : 'descr' , size : 50, 'maxlength' : 50,'value' : data.get ( 'descr' , '' ) } );
	_f.text ( { 'label' : 'Coupon' , 'name' : 'product_coupon' , size : 50, 'maxlength' : 50,'value' : data.get ( 'product_coupon' , '' ) } );
	_f.number ( { 'label' : 'Giorni preavviso', 'name' : 'day_before' , size : 10, 'maxlength' : 10, 'value' : data.get ( 'day_before', 1 ) } );
	_f.money ( { 'label' : 'Costo' , 'name' : 'value' , onchange : "course.admin.charge_set_end_value()", size : 10, 'maxlength' : 10, 'value' : data.get ( 'value' , 0 ) } );
	_f.number ( { 'label' : 'IVA', 'name' : 'tax_code' , size : 10, 'maxlength' : 10, 'value' : data.get ( 'tax_code', 21 ) } );
	_f.money ( { 'label' : 'Costo Finale', 'name' : 'end_value' ,onchange : "course.admin.charge_set_value()",  size : 10, 'maxlength' : 10, 'value' : data.get ( 'end_value', 0 ) } );
   	_f.submit ( { value: 'Salva', 'class' : "button green", nonl : true } );
	_f.button ( { value: 'Annulla', 'class' : "grey", onclick : "course.admin._charge_refresh()"} );
	_f.set ( dest_div );
	course.admin._show_cnt ( 'co_charge_panel_form', 'charge' );
	
};
//}}}
course.admin.charge_set_end_value = function ()
{
	var f = liwe.form.get ( 'am_charge_form' );
	var value = f.get_value ( 'value', 0 )
	if ( value == 0 ) return;
	if ( value.indexOf ( ',' ) == -1 ) value = value + "00";
	value = value.replace ( ",", "").replace ( "." , "" );
	var tax = 1 + ( f.get_value ( 'tax_code'  ) / 100 );
	var end_value = Math.round ( value * tax ); 
	f.set_value ( "end_value",	Money.fromLongInt ( end_value ) );
	
}
course.admin.charge_set_value = function ()
{
	var f = liwe.form.get ( 'am_charge_form' );
	
	var end_value = f.get_value ( 'end_value', 0 )
	if ( end_value == 0 ) return;
	if ( end_value.indexOf ( ',' ) == -1 ) end_value = end_value + "00";
	end_value = end_value.replace ( ",", "").replace ( "." , "" );
	var tax = 1 + ( f.get_value ( 'tax_code'  ) / 100 );
	var value = Math.round ( end_value / tax ); 
	f.set_value ( "value",	Money.fromLongInt ( value ) );
}

//}}}
//{{{CALENDAR
course.admin._render_calendar = function ()
{
	var _dct, _admin_title;
	_admin_title = String.formatDict ( course.templates [ 'ADMIN_TITLE' ], { '_title' : 'Calendario Corsi' } );
	_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco', '_form_title' : "Inserimento/modifica corso"  };
	$( course.admin._dest_div, String.formatDict ( course.templates [ 'ADMIN_CALENDAR_LAYOUT' ], _dct ) );
	course.admin._calendar_refresh ();
};
//{{{course.admin._am_calendar_init = function ( dest_div )
course.admin._am_calendar_init = function ( dest_div )
{
        if ( course.admin.am_calendar ) return;
        course.admin.am_calendar = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_calendar',
         	                            'list_action': "course.ajax.list_calendar",
										'del_action' : "course.admin.del_calendar",
                                        'mod_menu_actions': [
                                                                 { func: "course.admin._calendar_form();", 'class' : 'add' , label: 'Aggiungi Corso' }
															],
										'filter_form' : course.admin._calendar_filter_form,
										'filter_form_name' : "am_calendar_filter"
                                } );

        course.admin.am_calendar.set_row_fields (
                                [
                                        [ "ID", "id" ],
                                        [ "Data Inizio", "_start_date" ],
										[ "Posti", "_places" ],
										[ "Iscritti", "_members" ],
                                        [ "Tutor", "_tutor" ],
                                        [ "Note", "descr" ]
                                ]
                                );

        course.admin.am_calendar.cbacks [ 'row_manip' ] = course.admin._rwman_calendar;
        course.admin.am_calendar.cbacks [ 'del_item' ]  = function ( id ) { course.admin.del_calendar ( id ); };
        course.admin.am_calendar.cbacks [ 'edit_item' ]  = function ( id ) { course.admin.edit_calendar ( id ); };
        course.admin.am_calendar.cbacks [ 'noresult' ] = function () { course.admin._calendar_form(); };
        course.admin.am_calendar.cbacks [ 'show_results' ] = function () { course.admin._show_cnt ( 'co_calendar_panel_list', 'calendar' ); };
};
//}}}
//{{{course.admin._calendar_filter_form = function ( dest_div )
course.admin._calendar_filter_form = function ( dest_div )
{
	course.admin._get_id_course ();
	var f = new liwe.form.instance ( "am_calendar_filter" );
	f.hidden ( "id_course", course.admin._id_course );
	f.set ( dest_div );
	
	
};
//}}}
//{{{course.admin._rwman_calendar = function ( ds, row )
course.admin._rwman_calendar = function ( ds, row )
{
        row [ "_id" ] = row [ 'id' ];
	row [ "_start_date" ] = Date.formatted ( "%d %B %Y", row [ 'start_date' ].split( " ") [ 0 ]) ; 

	var user =  course.admin._get_user_mail ( 'teacher' , row [ 'uid_trainer' ]  );
	row [ "_tutor" ] = String.formatDict ( course.templates [ 'ADMIN_USER_CARD' ],  user ) ;


	var _dct = { '_class' : 'number' };
	_dct [ '_txt' ] = ( row [ 'places' ] ) ;
	row [ "_places" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );

	_dct [ '_txt' ] = ( row [ 'members' ] ) ;
	if ( row [ 'members' ] > row [ 'places' ] ) _dct [ '_class' ] = 'number red';
	row [ "_members" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
};
//}}}
//{{{course.admin._calendar_refresh =  function ( cback )
course.admin._calendar_refresh =  function ( cback )
{
        course.admin.am_calendar.show_list ();
	if ( cback ) cback();
};
//}}}
//{{{course.admin.edit_calendar = function ( id )
course.admin.edit_calendar = function ( id )
{
        var _post = { action : 'course.ajax.get_calendar', id_calendar : id };
        course.ajax ( _post , function ( _resp )
        {      
		course.admin._calendar_form ( _resp.calendar );
        });
};
//}}}
//{{{course.admin._calendar_save =  function ()
course.admin._calendar_save =  function ()
{
	course.admin._calendar_refresh ( function () 
	{
		liwe.utils.notifier.show ( 'Data Salvata correttamente', 'info', 2000)
	});	
};
//}}}
//{{{course.admin.del_calendar = function ( ids )
course.admin.del_calendar = function ( ids )
{
	var answer = confirm("Sei sicuro di vole cancellare questa data?");
	if ( answer )
	{
		var v = { 'action' : 'course.admin.del_calendar', 'ids' : ids };
		course.admin.ajax ( v , function ()
		{
			liwe.utils.notifier.show ( 'Data/e elimanta/e', 'info', 2000)
			course.admin.am_calendar.show_list();
		});
	} else {
		return;
	};
};  
//}}}
//{{{course.admin._calendar_form =  function ( data )
course.admin._calendar_form =  function ( data )
{
	var dest_div = 'co_calendar_form';
	if ( typeof ( data ) == 'undefined' ) 
	{
		data = {};
		data [ 'id_course' ] = course.admin._get_id_course (); 
	};
	var _f = new liwe.form.instance ( 'am_calendar_form' );
	_f.events [ 'complete' ] = course.admin._calendar_save;
	_f.hidden ( "action", 'course.admin.set_calendar' );
	_f.hidden ( 'id_calendar', data.get ( 'id', 0 )  );
	_f.hidden ( 'id_course', data.get ( 'id_course', 0 )  );
	_f.calendar ( { 'label' : 'Data Inizio', name: 'start_date', time: true, 'nonl' : true, value : data.get ( 'start_date', Date.formatted ( "%Y-%m-%d %h:%m:%s", Date() ) )  } );
	_f.select ( { label: 'Insegnante', name: 'uid_trainer', options: course._user_opts [ 'teacher' ] , force_select: true, 'value' : data.get ( 'uid_trainer' , 0 ) } );
	_f.text ( { 'label' : 'Citt&agrave;' , 'name' : 'city' , size : 30, 'maxlength' : 50, 'nonl' : true, 'value' : data.get ( 'city' , '' ) } );
	_f.jconed ( { 'label' : 'Indirizzo', 'name' : "address", width: 300, height: 50, colspan : 3, 'value' : data.get ( 'address' , '' ) } );
	_f.jconed ( { 'label' : 'Note', 'name' : "descr", colspan : 5,  width: 300, height: 100, 'value' : data.get ( 'descr' , '' ) } );
	_f.submit ( { value: 'Salva', 'class' : "button green", nonl : true, colspan : 3 } );
	_f.button ( { value: 'Annulla', 'class' : "grey", onclick : "course.admin._calendar_refresh()"} );
	_f.set ( dest_div );
	course.admin._show_cnt ( 'co_calendar_panel_form', 'calendar' );
	
};
//}}}
//}}}
//{{{USER
//{{{course.admin._am_user_init = function ( dest_div )
course.admin._am_user_init = function ( dest_div )
{
        if ( course.admin.am_user ) return;
        course.admin.am_user = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_user',
                                        'list_action': "course.ajax.list_user",
                                        'mod_menu_actions': [
                                                                 { func: "course.admin._user_form();", 'class' : 'add' , label: 'Aggiungi Corso' }
					],
					'filter_form' : course.admin._user_filter_form,
					'filter_form_name' : "am_user_filter"
                                } );

        course.admin.am_user.set_row_fields (
                                [
                                        [ "Utente", "_utente" ],
                                        [ "Titolo Corso", "course" ],
                                        [ "Data Inizio Corso", "_start_date" ],
                                        [ "Data Iscrizione", "_subscription_date" ],
                                        [ "Costo Iscrizione", "_pay" ],
                                        [ "Ha Pagato", "_paid" ],
                                        [ "Residuo", "_residue" ]
                                ]
                                );

        course.admin.am_user.cbacks [ 'row_manip' ] = course.admin._rwman_user;
        course.admin.am_user.cbacks [ 'del_item' ]  = function ( id ) { course.admin.del_user ( id ); };
        course.admin.am_user.cbacks [ 'edit_item' ]  = function ( id ) { course.admin.edit_user ( id ); };
        course.admin.am_user.cbacks [ 'noresult' ] = function () { course.admin._user_form(); };
        course.admin.am_user.cbacks [ 'show_results' ] = function () { course.admin._show_cnt ( 'co_user_panel_list', 'user' ); };
};
//}}}
//{{{course.admin._user_filter_form = function ( dest_div )
course.admin._user_filter_form = function ( dest_div )
{

	var id_course = course.admin._get_id_course ();
	var f = new liwe.form.instance ( "am_user_filter" );
	f.hidden ( "id_course", id_course );
	if ( course.admin._user_date_opts ) 
	{
		var id_cal = course.admin._user_date_opts [ 0 ] [ 'value' ];
		if (  course.admin._user_date_opts.length == 1 )
		{
			f.hidden ( "id_calendar", id_cal );
			
		}else{
			f.select ( { label: 'Data Corso', name: 'id_calendar', options: course.admin._user_date_opts, 'value' : id_cal } );
			f.button ( { value: "Applica Filtro", "class" : "green", onclick: "course.admin.am_user.search_start()" } );
		}
	}
	f.set ( dest_div );
};
//}}}
//{{{course.admin._rwman_user = function ( ds, row )
course.admin._rwman_user = function ( ds, row )
{
	var _dct = { '_class' : 'money' };
        row [ "_id" ] = row [ 'id' ];
	row [ "_subscription_date" ] = Date.formatted ( "%A %d %B %Y", row [ 'subscription_date' ].split( " ") [ 0 ]) ;
	row [ "_start_date" ] = Date.formatted ( "%A %d %B %Y", row [ 'start_date' ].split( " ") [ 0 ]) ;
	_dct [ '_txt' ] ='€ ' +  Money.fromLongInt ( row [ 'pay' ] - row [ 'paid' ] ) ;
	row [ "_residue" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
	_dct [ '_txt' ] = '€ ' + Money.fromLongInt ( row [ 'pay' ] );
	row [ "_pay" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct );
	_dct [ '_txt' ] = '€ ' + Money.fromLongInt ( row [ 'paid' ] );
	row [ "_paid" ] = String.formatDict ( system.templates [ 'admin_man_col' ] , _dct ); 
 
	var user =  course.admin._get_user_mail ( 'student' , row [ 'uid' ]  ); 	
	row [ "_utente" ] = String.formatDict ( course.templates [ 'ADMIN_USER_CARD' ],  user ) ;

};
//}}}
//{{{course.admin._user_refresh =  function ( cback )
course.admin._user_refresh =  function ( cback )
{
	var id_course = course.admin._get_id_course ();
	var post = { 'action' : 'course.admin.distinct_date_user' , id_course : id_course };
	course.ajax ( post , function ( res )
	{
		if ( res.dates )
		{
			var dates = list ( res.dates );
			var opts = list();
			dates.iterate ( function ( date )
			{
				opts.push ( { 'label' :  Date.formatted ( "%A %d %B %Y", date [ 'start_date' ].split( " ") [ 0 ]), 
								'value' : date [ 'id_calendar' ] } );
			} );
			course.admin._user_date_opts = opts;
		}
		course.admin.am_user.show_list ();
		if ( cback ) cback();
	} );
};
//}}}
//{{{course.admin.edit_user = function ( id )
course.admin.edit_user = function ( id )
{
        var _post = { action : 'course.ajax.get_user', id_user : id };
        course.ajax ( _post , function ( _resp )
        {      
		course.admin._user_form ( _resp.user );
        });
};
//}}}
//{{{course.admin._user_save =  function ()
course.admin._user_save =  function ()
{
	course.admin._user_refresh ( function () 
	{
		liwe.utils.notifier.show ( 'Data Salvata correttamente', 'info', 2000)
	});	
};
//}}}
//{{{course.admin.del_user = function ( ids )
course.admin.del_user = function ( ids )
{
	var answer = confirm("Sei sicuro di vole cancellare questo studente?");
	if ( answer )
	{
		var v = { 'action' : 'course.admin.del_user', 'ids' : ids };
		course.admin.ajax ( v , function ()
		{
			liwe.utils.notifier.show ( 'Studente/i elimanto/i', 'info', 2000)
			course.admin.am_user.show_list();
		});
	} else {
		return;
	};
};
//}}}
//{{{course.admin._user_form =  function ( data )
course.admin._user_form =  function ( data )
{
	var dest_div = 'co_user_form';
	var _f = new liwe.form.instance ( 'am_user_form' );
	_f.events [ 'complete' ] = course.admin._user_save;
	_f.hidden ( "action", 'course.admin.set_user' );
	var _id_course = 0;
	if ( typeof ( data ) == 'undefined' )	data = {};

	_f.hidden ( 'id_user', data.get ( 'id', 0 ) );	
	//var _fcourse = liwe.form.get ( 'am_course_form' );
	if ( data.get ( 'id_course', -1 ) == -1 )
	{
		data [ 'id_course' ] = course.admin._get_id_course (); 
	};
	if ( typeof ( _fcourse ) != 'undefined' )
	{
		_f.hidden ( 'id_course', data [ 'id_course' ] );	
	} else {
	
		_f.select ( { label: 'Corso', name: 'id_course', options: course._course_opts , force_select: true, 'value' : data.get ( 'id_course'  , 0 ) } );
	};

	course.admin._set_calendar_opts ( _id_course, function () 
	{
		if ( typeof ( course.admin.am_calendar.get_selected_row() ) != 'undefined' )
		{
			data [ 'id_calendar' ] = course.admin.am_calendar.get_selected_row().get ( 'id', 0 ) ;
		};
		_f.select ( { label: 'Calendario', name: 'id_calendar', options: course._calendar_opts , force_select: true, 'value' : data.get ( 'id_calendar' , 0 ) } );
		_f.select ( { label: 'Utente', name: 'uid', options: course._user_opts [ 'student' ], force_select: true, 'value' : data.get ( 'uid' , 0 ) } );
		_f.calendar ( { 'label' : 'Data Iscrizione', name: 'subscription_date', time: false, 'value' : data.get ( 'subscription_date', Date.formatted ( "%Y-%m-%d", Date() ) )  } );
		_f.money ( { 'label' : 'Costo Corso', name : 'pay', size : 10, 'maxlength' : 10, 'value' : data.get ( 'pay', 0 ) } );
		_f.money ( { 'label' : 'Ha pagato', name : 'paid', size : 10, 'maxlength' : 10, 'value' : data.get ( 'paid', 0 ) } );
		_f.jconed ( { 'label' : 'Note', 'name' : "note", colspan : 3,  width: 300, height: 200, 'value' : data.get ( 'note' , '' ) } );
		_f.submit ( { value: 'Salva', 'class' : "button green", nonl : true } );
		_f.button ( { value: 'Annulla', 'class' : "grey", onclick : "course.admin._user_refresh()"} );
		_f.set ( dest_div );
		course.admin._show_cnt ( 'co_user_panel_form', 'user' );
	})
	
};
//}}}
//}}}
//}}}
//{{{****************JCONED PLUGIN****************+
//{{{ LISTA CORSI
//{{{course.admin._jconed_form = function ( values )
course.admin._jconed_form = function ( values )
{
	values = values || {};
	var _categ = '';
	var _post = { 'action' : 'tags.ajax.tags_list_all' , 'module' : 'course' };
	course.ajax ( _post , function ( _resp )
	{
		var _find = {};
		var _opts = [];
		_resp.tags.iterate( function ( tag )
		{
			if ( _find.get ( tag [ 'id' ], 0 ) == 0 ) _find [ tag [ 'id' ] ] = tag;
		});
		_find.iterate ( function ( tag )
		{
			_opts.push ( { 'label' : tag [ 'name' ] , 'value' : tag [ 'name' ] } );
			// FIXME: bundle, guarda se sta riga serve!! if ( values.get ( 'tag', 0 ) == tag [ 'name' ] );
		});
		f = new liwe.form.instance ( 'jconed-course' );
		f.hidden ( '_module', 'course' );
		f.hidden ( '_type', 'list' );
		
		var d = new Date()

		f.hidden ( '_title', 'Corsi ' + _categ  );
		f.hidden ( '_name', d.getTime()  );
		
		f.select ( { name: 'tag', options: _opts, force_select: true, label: 'Tipo Corso', value: values.get ( 'tag', 0 ) } );
		f.number ( { name: 'how_many', label : 'Elementi per pagina', mandatory : true, size : 4 , value : values.get ( 'how_many', 10 ) } ) ;
		f.check_box ( { label: 'Solo Titoli con date valide', name: 'incoming', checked : !!parseInt ( values.get ( 'incoming', 0 ) ), 'value' : 1  } );
		f.button ( { value: "Conferma", onclick: "course.admin._render_plugin()" } );
		jconed.toolbar.set_context ( f.get() );
	});

};
//}}}
//{{{course.admin._render_plugin = function ()
course.admin._render_plugin = function ()
{
	var _f = liwe.form.get ( 'jconed-course' );
	var _select = f.get_element ( 'tag' );
	var _categ = _select.options [ _select.options.selectedIndex ].text;
	f.set_value ( '_title' , 'Corsi ' + _categ );
	
	jconed.render_plugin('jconed-course');
	
};
//}}}
//{{{course.admin._jconed_handler = function ()
course.admin._jconed_handler = function ()
{
       	course.admin._jconed_form ();
};
//}}}
//{{{course.admin._jconed_context = function ()
course.admin._jconed_context = function ()
{
        var item = jconed.get_plugin_selection ();
        if ( ! item ) return;
        if ( ! liwe.dom.has_class ( item, 'liwe-plugin-course' ) ) return;

        pre = item.getElementsByTagName ( "pre" );
        if ( ! pre.length ) return;

        pre = pre [ 0 ];

        var values = null;
        eval ( 'values = ' + pre.innerHTML );

        //if ( typeof ( values ) != 'object' ) return; 

        course.admin._jconed_form ( values [ 'params' ] );

};
//}}}
//}}}
//{{{ INCOMING

course.admin._jconed_incoming_form = function ( data )
{
		if ( typeof ( data == 'undefined'  ) ) data = dict ();

		f = new liwe.form.instance ( 'jconed-course-incoming' );
		f.hidden ( '_module', 'course' );
		f.hidden ( '_type', 'incoming' );
		f.number ( { name: 'how_many', label : 'Numero di elementi da mostrare', mandatory : true, size : 4 , value : data.get ( 'how_many', 10 ) } ) ;
		f.text ( { 'label' : 'Formattazione data' , 'name' : 'date_format',  size : 40, 'maxlength' : 10, 'value' : data.get ( 'date_format' , '%d/%B/%Y' ) } );
		f.button ( { value: "Conferma", onclick: "jconed.render_plugin('jconed-course-incoming')" } );
		jconed.toolbar.set_context ( f.get() );
};
course.admin._jconed_incoming_ctx = function ()
{

		var item = jconed.get_plugin_selection ();
        if ( ! item ) return;
        if ( ! liwe.dom.has_class ( item, 'liwe-plugin-course' ) ) return;

        pre = item.getElementsByTagName ( "pre" );
        if ( ! pre.length ) return;

        pre = pre [ 0 ];

        var values = null;
        eval ( 'values = ' + pre.innerHTML );

        //if ( typeof ( values ) != 'object' ) return; 

        course.admin._incoming_form ( dict ( values [ 'params' ] ) );

};
course.admin._jconed_incoming_hd = function ()
{
       	course.admin._jconed_incoming_form ();
};
//}}}
//}}}
//{{{course.admin.init = function ( dest_div )
course.admin.init = function ( dest_div )
{
	if ( ! course.templates )
	{
		course.load_templates ( function () { course.admin._init ( dest_div); } );
		return;
	}
	course.admin._init ( dest_div );
};
//}}}
